import React, { Component } from 'react';
class CommentHeader extends Component {
    state = { 
      title: '',
      desc: ''
    } 
    
    handleTitle = (e) => {
      this.setState({
         title: e.target.value
      })
    }
    
    handleDesc = (e) => {
        this.setState({
            desc: e.target.value
         })
    }
    
    // 发表评论
    publishComment = () => {
      const { title, desc} = this.state
    // console.log({title, desc})
    this.props.updateList({title, desc})
    this.setState({
       title: '',
       desc: ''
    }) 
    }
    render() { 
        return (<div>
          <header>
             <input type="text" value={this.state.title} placeholder='请输入标题' onChange={this.handleTitle} />
             <textarea cols="30" rows="10" value={this.state.desc}  placeholder='请输入内容' onChange={this.handleDesc}></textarea>
             <button onClick={this.publishComment}>发表评论</button>
          </header>
        </div>);
    }
}
 
export default CommentHeader;